package com.lge.clock.test;

import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;
import android.widget.Button;

import com.jayway.android.robotium.solo.Solo;
import com.lge.clock.R;
import com.lge.clock.TimerActivity;
import com.lge.inner_sui.widget.control.SUIDrumTimePicker;

public class TimerActivityTest_hyunyong extends ActivityInstrumentationTestCase2<TimerActivity>{
	private TimerActivity mTimerActivity = null;
	private Button mTimer_start_btn = null;
	private Button mTimer_cancle_btn = null;
	private SUIDrumTimePicker mTimePicker = null;
	private Solo solo;
	
	public TimerActivityTest_hyunyong() {
		super("com.lge.clock",TimerActivity.class);
	}

	@Override
	protected void setUp() throws Exception {
		solo = new Solo(getInstrumentation(),getActivity());
		mTimerActivity = getActivity();	
		setActivityInitialTouchMode(false);
		mTimer_start_btn = (Button)mTimerActivity.findViewById(R.id.timer_start_btn);
		mTimer_cancle_btn = (Button)mTimerActivity.findViewById(R.id.timer_cancel_btn);
		mTimePicker = (SUIDrumTimePicker)mTimerActivity.findViewById(R.id.timepicker);
		getActivity();
		super.setUp();
	}

	@Override
	protected void tearDown() throws Exception {
		try{
			solo.finalize();
		}catch(Throwable e){
			getActivity().finish();
		}
		getActivity().finish();
		super.tearDown();
	}
	
	
	public void testSouldBeWhenTouchHomeKeyTheAlarmStartedTimerInSleep(){
		solo.clickOnView(mTimer_cancle_btn);
		mTimerActivity.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				mTimePicker.setCurrentHour(0);
				mTimePicker.setCurrentMinute(0);
				mTimePicker.setCurrentSecond(3);

			}
		});

		solo.clickOnView(mTimer_start_btn);
		solo.sendKey(KeyEvent.KEYCODE_HOME);
		SystemClock.sleep(3000);
		assertTrue(solo.searchText(getActivity().getString(R.string.timer_done)));
		SystemClock.sleep(500);
	}
	
	public void testSouldBeWhenTouchBackKeyTheAlarmStartedTimerInSleep(){
		solo.clickOnView(mTimer_cancle_btn);
		mTimerActivity.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				mTimePicker.setCurrentHour(0);
				mTimePicker.setCurrentMinute(0);
				mTimePicker.setCurrentSecond(3);

			}
		});

		solo.clickOnView(mTimer_start_btn);
		solo.sendKey(KeyEvent.KEYCODE_BACK);
		SystemClock.sleep(4000);
		assertTrue(solo.searchText(getActivity().getString(R.string.timer_done)));
		
	}
	
}
